import 'package:yqmssa_app/request/http_path.dart';
import 'package:yqmssa_app/request/my_request.dart';

class SplashMethods {
  SplashMethods._();

  ///初始化
  static Future<AppInitDM> appInit() async {
    final res = await MyRequest().dioReq(HttpPath.appInit);
    return AppInitDM.fromJson(res["data"]);
  }

  static Future<XieYiDM> xieYi() async {
    final res = await MyRequest().dioReq(HttpPath.xieYi);
    return XieYiDM.fromJson(res["data"]);
  }
}

class AppInitDM {
  late int isLogin;
  late int isOpenVideo;
  late String version;
  late String logo;
  late String title;
  late String subtitle;
  late int isOpenAb;
  late int submitPage;
  late int jumpXcx;
  late int viewList;
  late int openQuestion;
  late int openQuestionBao;
  late String xcxId;
  late String openChat;
  late String slogan;
  late int jumpScan;
  late int isXcx;
  late int isChat;
  late int isLink;
  late int havePop;
  late int haveCall;
  late int havePartnerOpen;
  late String partnerDescribe;
  late String partner;
  late String icpRecord;
  late ChannelText? channelText;
  late int indexSubmit;
  late int indexSubmitType;
  late String submitPicture;
  late int chatBot;
  late BannerImageSet? bannerImageSet;
  late AddWxButton? addWxButton;

  AppInitDM({
    this.isLogin = 0,
    this.isOpenVideo = 0,
    this.version = "",
    this.logo = "",
    this.title = "",
    this.subtitle = "",
    this.isOpenAb = 0,
    this.submitPage = 0,
    this.jumpXcx = 1,
    this.viewList = 1,
    this.openQuestion = 0,
    this.openQuestionBao = 0,
    this.icpRecord = "",
    this.slogan = "",
    this.isXcx = 1,
    this.isChat = 1,
    this.isLink = 1,
    this.xcxId = "",
    this.openChat = "",
    this.jumpScan = 0,
    this.havePartnerOpen = 0,
    this.partnerDescribe = "",
    this.partner = "",
    this.channelText,
    this.chatBot = 0,
    this.havePop = 0,
    this.haveCall = 0,
    this.indexSubmit = 0,
    this.indexSubmitType = 0,
    this.submitPicture = "",
    this.bannerImageSet,
    this.addWxButton,
  });

  AppInitDM.fromJson(Map<String, dynamic> json) {
    isLogin = json['is_login'];
    isOpenVideo = json['is_open_video'];
    version = json['version'];
    logo = json['logo'];
    title = json['title'];
    subtitle = json['subtitle'];
    isOpenAb = json['is_open_ab'];
    submitPage = json['submit_page'];
    jumpXcx = json['jump_xcx'];
    viewList = json['view_list'];
    openQuestion = json['open_question'];
    openQuestionBao = json['open_question_bao'];
    xcxId = json['xcx_id'];
    openChat = json['open_chat'];
    jumpScan = json['jump_scan'];
    slogan = json['slogan'];
    isXcx = json['is_xcx'] ?? 0;
    isChat = json['is_chat'] ?? 0;
    isLink = json['is_link'] ?? 0;
    havePop = json["have_pop"] ?? 0;
    haveCall = json["have_call"] ?? 0;
    havePartnerOpen = json['have_partner_open'];
    partnerDescribe = json['partner_describe'];
    partner = json['partner'];
    icpRecord = json['icp_record'];
    channelText = ChannelText.fromJson(json["channel_text"] ?? {});
    chatBot = json["chat_bot"] ?? 0;
    indexSubmit = json["index_submit"] ?? 0;
    indexSubmitType = json["index_submit_type"] ?? 0;
    submitPicture = json["submit_picture"] ?? "";
    bannerImageSet = BannerImageSet.fromJson(json["banner_image_set"] ?? {});
    addWxButton = json["add_wx_button"] == null ? AddWxButton() : AddWxButton.fromJson(json["add_wx_button"]);
  }

  void loginReplaceData(Map<String, dynamic> json) {
    jumpXcx = json['jump_xcx'];
    openChat = "${json['open_chat'] ?? 0}";
    isLink = json['is_link'];
    jumpScan = json['jump_scan'];
    isOpenAb = json['is_open_ab'];
    isXcx = json['is_xcx'];
    isChat = json['is_chat'];
    chatBot = json['chat_bot'];
    havePop = json['have_pop'];
    haveCall = json['have_call'];
    addWxButton = json["add_wx_button"] == null ? AddWxButton() : AddWxButton.fromJson(json["add_wx_button"]);
  }
}

class ChannelText {
  ChannelText({
    this.loginTitle = "",
    this.appTitle = "",
    this.appSubtitle = "",
    this.listText = "",
    this.detailText = "",
    this.submitText = "",
    this.loginSubtitle = "",
    this.chatWeText = "",
    this.chatLayerText = "",
    this.chatPicture = "",
  });

  late String loginTitle;
  late String loginSubtitle;
  late String appTitle;
  late String appSubtitle;
  late String listText;
  late String detailText;
  late String submitText;
  late String chatWeText;
  late String chatLayerText;
  late String chatPicture;

  factory ChannelText.fromJson(Map<String, dynamic> json) {
    return ChannelText(
      loginTitle: json["login_title"] ?? "",
      loginSubtitle: json["login_subtitle"] ?? "",
      appTitle: json["app_title"] ?? "",
      appSubtitle: json["app_subtitle"] ?? "",
      listText: json["list_text"] ?? "",
      detailText: json["detail_text"] ?? "",
      submitText: json["submit_text"] ?? "",
      chatWeText: json["chat_we_text"] ?? "",
      chatLayerText: json["chat_layer_text"] ?? "",
      chatPicture: json["chat_picture"] ?? "",
    );
  }
}

class BannerImageSet {
  BannerImageSet({
    this.bannerImage = "",
    this.bannerImageOpen = 0,
    this.bannerImageType = 0,
  });

  late String bannerImage;
  late int bannerImageOpen;
  late int bannerImageType;

  BannerImageSet.fromJson(Map<String, dynamic> json) {
    bannerImage = json['banner_image'] ?? "";
    bannerImageOpen = json['banner_image_open'] ?? 0;
    bannerImageType = json['banner_image_type'] ?? 1;
  }
}

class AddWxButton {
  AddWxButton({
    this.addWxView = 0,
    this.chatWeText = "",
  });

  late int addWxView;
  late String chatWeText;

  factory AddWxButton.fromJson(Map<String, dynamic> json) {
    return AddWxButton(
      addWxView: json["add_wx_view"] ?? 0,
      chatWeText: json["chat_we_text"] ?? "",
    );
  }
}

class XieYiDM {
  XieYiDM({this.privacyAgreementUrl = "", this.userAgreementUrl = ""});
  late final String userAgreementUrl;
  late final String privacyAgreementUrl;

  XieYiDM.fromJson(Map<String, dynamic> json) {
    userAgreementUrl = json['user_agreement_url'];
    privacyAgreementUrl = json['privacy_agreement_url'];
  }
}
